package com.bss.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.andy.basics.Dao;
import com.bss.dao.ActivityDao;
import com.bss.dao.AdmissionDao;
import com.bss.model.Admission;

@Service
public class GenericService extends com.andy.basics.Service<Admission> {

	@Autowired
	private AdmissionDao admissionDao;

	@Autowired
	private ActivityDao activityDao;

	private List<Admission> checkins;

	private List<Admission> checkouts;

	@Override
	public Dao<Admission> getDao() {
		return this.admissionDao;
	}

	public List<Admission> getLastCheckins() {
		if (this.checkins == null) {
			Date date = this.activityDao.findLastDepositAndRefundReportActivityDate();
			if (date != null) {
				this.checkins = this.admissionDao.findWithParameters("dateOfAdmission > ?", date);
			}
		}
		return this.checkins;
	}

	public List<Admission> getLastCheckouts() {
		if (this.checkouts == null) {
			Date date = this.activityDao.findLastDepositAndRefundReportActivityDate();
			if (date != null) {
				this.checkouts = this.admissionDao.findWithParameters("dateOfExit > ?", date);
			}
		}
		return this.checkouts;
	}

	public void reloadCheckins() {
		this.checkins = null;
	}

	public void reloadCheckOuts() {
		this.checkouts = null;
	}
}
